package com.gome.gop.data.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;

/**
 * @ClassName: TreeItem
 * @Description: EasyUI Tree节点数据结构
 * @author: Administrator
 */
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class TreeItem implements Cloneable, Serializable{
    /**
	 * 
	 */
	private static final long serialVersionUID = 7524185467522018192L;

	/**
     * 节点ID
     */
    private String id;

    /**
     * 节点显示名称
     */
    private String text;

    /**
     * 节点展开属性
     */
     private String state;
     
     /**
      * 节点图标属性
      */
     private String iconCls;
     
    /**
     * 子节点列表
     */
    private List<TreeItem> children;

    /**
     * 节点属性
     */
    private Map<String, String> attributes;

    /**
     * 扩展字段
     */
    @JsonIgnore
    private String memo;
    
    /**
	 * 是否选中
	 */
	private boolean checked;

    /**
     * Clone树节点
     * 
     * @return 树节点
     */
    public Object clone() {
        TreeItem o = null;
        try {
            o = (TreeItem) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return o;
    }

    /**
     * 是否有子节点
     * 
     * @return true: has Children; false: No children
     */
    public boolean hasChildren() {
        if (this.children == null || this.children.isEmpty()) {
            return false;
        }
        return true;
    }
    
    /**
     * 创建子节点列表
     * 
     * @return 子节点列表
     */
    public List<TreeItem> createChildren() {
        if (this.children == null) {
            this.children = new ArrayList<TreeItem>();
        }
        return this.children;
    }

    /**
     * 添加属性. 
     * @param key           key
     * @param value         value
     */
    public void addAttribute(String key, String value) {
        if (this.attributes == null) {
            this.attributes = new HashMap<String, String>();
        }
        this.attributes.put(key, value);
    }
    
    /**
     * 获取节点ID
     * 
     * @return 节点ID
     */
    public String getId() {
        return id;
    }

    /**
     * 设置节点ID
     * 
     * @param id
     *            节点ID
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * 获取节点显示名称
     * 
     * @return 节点显示名称
     */
    public String getText() {
        return text;
    }

    /**
     * 设置节点显示名称
     * 
     * @param text
     *            节点显示名称
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     * 获取节点展开属性
     * 
     * @return 节点展开属性
     */
    public String getState() {
        return state;
    }

    /**
     * 设置节点展开属性
     * 
     * @param state
     *            节点展开属性
     */
    public void setState(String state) {
        this.state = state;
    }

    /**
     * 获取节点图标属性
     * 
     * @return 节点图标属性
     */
    public String getIconCls() {
        return iconCls;
    }

    /**
     * 设置节点图标属性
     * 
     * @param iconCls
     *            节点图标属性
     */
    public void setIconCls(String iconCls) {
        this.iconCls = iconCls;
    }
    
    /**
     * 获取子节点列表
     * 
     * @return 子节点列表
     */
    public List<TreeItem> getChildren() {
        return children;
    }

    /**
     * 设置子节点列表
     * 
     * @param children
     *            子节点列表
     */
    public void setChildren(List<TreeItem> children) {
        if (children != null && children.size() == 0) {
            this.children = null;
        }
        this.children = children;
    }

    /**
     * 获取节点属性
     * 
     * @return 节点属性
     */
    public Map<String, String> getAttributes() {
        return attributes;
    }

    /**
     * 设置节点属性
     * 
     * @param attributes
     *            节点属性
     */
    public void setAttributes(Map<String, String> attributes) {
        this.attributes = attributes;
    }

    /**
     * 获取MEMO. 
     * @return  memo
     */
    public String getMemo() {
        return memo;
    }

    /**
     * 设置Memo. 
     * @param memo  memo
     */
    public void setMemo(String memo) {
        this.memo = memo;
    }

	public boolean getChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}

	@Override
	public String toString() {
		return "TreeItem [id=" + id + ", text=" + text + ", state=" + state + ", iconCls=" + iconCls + ", children="
				+ children + ", attributes=" + attributes + ", memo=" + memo + ", checked=" + checked + "]";
	}

    
}
